package com.ruixi.spring.transaction;


import com.ruixi.spring.configTransaction.ConfigTX;
import com.ruixi.spring.transaction.service.AccountService;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestTransaction {

    private AccountService accountService;

    //@Before
    public void getTemplateForXML(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("conf/transaction.xml");
        AccountService accountService = applicationContext.getBean("accountService", AccountService.class);
        this.accountService = accountService;
    }

    //通过配置类实现完全注解开发
    @Before
    public void getTemplateForConf(){
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConfigTX.class);
        AccountService accountService = applicationContext.getBean("accountService", AccountService.class);
        this.accountService = accountService;
    }

    @Test
    public void accountMoney(){
        //转帐操作
        this.accountService.accountMoney();
    }

}
